package main

import (
	"github.com/gin-gonic/gin"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

type User1 struct {
	Username string `json:"username" form:"username"`
	Pass     int    `json:"pass" form:"pass"`
	ID       int    `json:"id"  form:"userid"`
}

func main() {
	r := gin.Default()
	r.POST("/user", func(c *gin.Context) {
		user := &User1{}
		if err := c.ShouldBind(&user); err == nil {
			c.JSON(200, user)
		} else {
			c.JSON(200, gin.H{
				"err": err.Error(),
			})
		}

	})
	r.Run()
	dsn := "root:170815@tcp(10.1.3.10:3306)/lianxi?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
			NoLowerCase:   true,
		},
	})
	if err != nil {
		panic(err)
	}
	user1 := new(User1)
	//db.Create(&User1{"孙玉", 12345, 1})
	db.First(&user1)

}
